package cn.yunhe.service;

import cn.yunhe.dao.IUserDao;
import cn.yunhe.entity.User;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserService {

    SqlSession session=SqlSessionFactoryUtil.getSqlSession();

    IUserDao userDao=session.getMapper(IUserDao.class);

    /**
     * 用户注册
     * @param user
     * @return
     */

    public boolean userReg(User user){
        boolean flag=userDao.userReg(user);
        session.commit();
        session.close();
        return flag;
    }

    /**
     * 检测用户名是否注册
     * @param name
     * @return
     */

    public List<User> checkRegName(String name){

        return userDao.checkRegName(name);
    }

    /**
     * 用户登录
     * @param user
     * @return
     */
    public User userLogin(User user){
        return userDao.userLogin(user);
    }

    /**
     * 用户登录后更改状态
     * @param user
     * @return
     */
    public boolean userStateUpdate(User user){

        return userDao.userStateUpdate(user);
    }

}
